package com.okami.service;

import com.okami.entity.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author: TanJingyu
 * @create: 2020-07-03 14:05
 **/
@Component
public class OkamiUserDetailsService implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        if ("张飞".equals(s)){
            User user = new User();
            user.setUserName("张飞");
            user.setPassword(new BCryptPasswordEncoder().encode("123"));
            return user;
        }
        throw new UsernameNotFoundException("用户名不存在！");
    }
}
